package com.liugui.lambda;

/**
 * @ClassName: LambdaTest
 * @Author: liugui
 * @Date: 2020-11-05 10:00
 **/
public class LambdaTest {
    public static void main(String[] args) {
        LambdaTest test = new LambdaTest();
        //带有类型声明的表达式
        MathOperation mathOperation = (int a,int b) -> a + b;
        //没有类型声明的表达式
        MathOperation subOperation = ( a, b) -> a + b;
        //带有大括号、带有返回语句的表达式
        MathOperation multiplication  = ( int a,int b ) -> { return a * b;};


        System.out.println("10+5=" + test.operate(10,5,mathOperation) );
        System.out.println("10+5=" + test.operate(10,5,subOperation) );
        System.out.println("10*5=" + test.operate(10,5,multiplication) );


        // 没有括号的表达式
        GreetingServer greetService1 = message ->
                System.out.println("Hello " + message);

        // 有括号的表达式
        GreetingServer greetService2 = (message) ->
                System.out.println("Hello " + message);

        // 调用sayMessage方法输出结果
        greetService1.print("Shiyanlou");
        greetService2.print("Classmate");
    }

    private int operate(int a, int b, MathOperation mathOperation){
        return mathOperation.operation(a, b);
    }
}

interface MathOperation{
    int operation(int a,int b);
}

interface GreetingServer{
    void print(String message);
}

